package com.abstralabs.time;

import java.util.ArrayList;
import java.util.Calendar;


public class History{ 
	
	String activity;
	public int loop=0;         // 0 - inactive, 1 - active
	int sumDay=0;       //in second
	int sumDayLast=0;
	ArrayList <Long> year=new ArrayList<Long>();
	ArrayList <Long> month=new ArrayList<Long>();
	ArrayList <Long> day=new ArrayList<Long>();
	//ArrayList <Long> hour=new ArrayList<Long>();
	//ArrayList <Long> minute=new ArrayList<Long>();
	ArrayList <Long> second=new ArrayList<Long>();
	
	public History(String activity) {
		this.activity=activity;
	}
	
	public void saveHistory (Calendar calnow){
			
		year.add((long)calnow.get(Calendar.YEAR));
		month.add((long)calnow.get(Calendar.MONTH));
		day.add((long)calnow.get(Calendar.DAY_OF_MONTH));
		//hour.add((long)calnow.get(Calendar.HOUR));
		//minute.add((long)calnow.get(Calendar.MINUTE));
		second.add((long)calnow.get(Calendar.SECOND)+(long)calnow.get(Calendar.MINUTE)*60+(long)calnow.get(Calendar.HOUR)*3600);
		if (loop==1){
			loop=0;
			sumDay=(int) (sumDayLast+second.get(month.size()-1)-second.get(month.size()-2));
			sumDayLast=sumDay;
		}
		else loop=1;
		
	}
	
//	public void newDay(){
//		sumDay=0;
//		Calendar calnow=Calendar.getInstance();
//		if (loop==1)
//			sumDayLast=(int) (second.get(month.size()-1)-(int)calnow.get(Calendar.SECOND)-(int)calnow.get(Calendar.MINUTE)*60-(int)calnow.get(Calendar.HOUR)*3600);
//		else
//		sumDayLast=0;
//	}
	
	public void updateSumDay(){
		if (loop==1){
			Calendar calnow=Calendar.getInstance();
			sumDay=(int) (sumDayLast-second.get(month.size()-1)+(int)calnow.get(Calendar.SECOND)+(int)calnow.get(Calendar.MINUTE)*60+(int)calnow.get(Calendar.HOUR)*3600);
		}
	}
}